<?php
// 主页
namespace Huaname\Controller;

use Think\Controller;
use Home\Model\SiteModel;

class IndexController extends Controller {
	public function index() {
		
		// 读取缓存
		$cacheName = get_cache_name ( 'huaname_index' );
		$data = S ( $cacheName );
		if (! $data) {
			
			$data ['seo'] ['title'] = '常见花卉图片及名称大全 - ' . C ( 'site_name' );
			$data ['seo'] ['keywords'] = '花卉,花卉网,花卉名称,花卉名字,花卉图片及名称大全';
			$data ['seo'] ['description'] = '花卉名字网，包含了上千种常见花卉供您查阅和检索，每种花卉都有详细的内容介绍和配有相关的花卉图片。喜欢种植花卉的朋友可以常来查花卉名称。';
			
			$m = new SiteModel ();
			$data ['site'] = $m->where ( 1 )->order ( 'url asc' )->select ();
			S ( $cacheName, $data, C ( 'cache_time_long' ) );
		}
		$this->data = $data;
		$this->display ();
	}
	public function article() {
		$url = $_REQUEST ['url'];
		// 读取缓存
		$cacheName = get_cache_name ( 'huaname_info_' . $url );
		$data = S ( $cacheName );
		if (! $data) {
			$m = new SiteModel ();
			$data ['info'] = $info = $m->where ( 'url="' . $url . '"' )->find ();
			
			$data ['info'] ['thumb'] = str_replace ( '.', '_500_500.', $data ['info'] ['thumb'] );
			// 替换所有空格
			$info ['context'] = preg_replace ( "/\s/", '', $info ['context'] );
			$info ['context'] = preg_replace ( "/[\n\r\t]/", '', $info ['context'] );
			$info ['context'] = str_replace ( array (
					" ",
					"  ",
					"　",
					"<p><p>",
					"<p><br/></p>" 
			), '', strip_tags ( $info ['context'], '<p>,<br>' ) );
			
			$data ['info'] ['context'] = $info ['context'];
			$data ['seo'] ['title'] = $info ['name'] . ' - ' . C ( 'site_name' );
			$data ['seo'] ['keywords'] = $info ['keyword'] . ',' . $info ['name'] . '花卉';
			$data ['seo'] ['description'] = $info ['name'] . ' - ' . $info ['intro'];
			S ( $cacheName, $data, C ( 'cache_time_long' ) );
		}
		$this->data = $data;
		$this->display ();
	}
}
